const btn = document.querySelector('.input_sub')
const textIpt = document.querySelector('.input_txt')
const talkList = document.querySelector('.talk_list')

btn.addEventListener('click', async function () {
    const spoken = textIpt.value.trim()
    if (!spoken) {
        return alert('输入内容不能为空！')
    }
    textIpt.value = ''
     let li = document.createElement('li')
        li.className = 'right_word'
        li.innerHTML = `<img src="img/person02.png" />
            <span>${spoken}</span>`
        talkList.appendChild(li)
        resetui()
    const res = await axios({
        method:'get',
        url: 'http://ajax-api.itheima.net/api/robot',
        params: {
            spoken
        }
    })
    console.log(res.data.data.info.text);
    let robotLi = document.createElement('li')
        robotLi.className = 'left_word'
        robotLi.innerHTML = `<img src="img/person01.png" />
        <span>${res.data.data.info.text}</span>`
        talkList.appendChild(robotLi)
        resetui()
    
})
    textIpt.addEventListener('keyup', function (e) {
        if (e.key === 'Enter') {
            btn.click()
        }
        })